package com.cashmanager.server.db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.cashmanager.shared.vo.CashierCompany;

public class CashierCompanyDaoImpl implements ICashierCompanyDao {
	
	private static final String INS_COMPANY = "insert into " + SCHEMA_NAME + 
			".CASHIER_COMPANY(cashier_company_name, cashier_company_contact) values (?,?)";
	private static final String UPD_COMPANY = "update " + SCHEMA_NAME + 
			".CASHIER_COMPANY set cashier_company_name =?," +
			"cashier_company_contact = ? where " +
			"cashier_company_id = ?";
	@Override
	public void addCompany(CashierCompany comp) {
		Connection conn = null;
		try {
			conn = JDBCUtil.getInstance().getConnection();
			PreparedStatement stmt = conn.prepareStatement(INS_COMPANY);
			stmt.setString(1, comp.getCompanyName());
			stmt.setString(2, comp.getCompanyContact());
			stmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			JDBCUtil.closeConn(conn);
		}
	}

	@Override
	public void updCompany(CashierCompany comp) {
		Connection conn = null;
		try {
			conn = JDBCUtil.getInstance().getConnection();
			PreparedStatement stmt = conn.prepareStatement(UPD_COMPANY);
			stmt.setString(1, comp.getCompanyName());
			stmt.setString(2, comp.getCompanyContact());
			stmt.setInt(3, comp.getCompanyId());
			stmt.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			JDBCUtil.closeConn(conn);
		}		
	}

}
